<include file="public/layout" />
<body style="background-color: rgb(255, 255, 255); overflow: auto; cursor: default; -moz-user-select: inherit;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>城市合伙人管理</h3>
            </div>
        </div>
    </div>
    <!-- 操作说明 -->
    <!--<div id="explanation" class="explanation" style="color: rgb(44, 188, 163); background-color: rgb(237, 251, 248); width: 99%; height: 100%;">-->
        <!--<div id="checkZoom" class="title"><i class="fa fa-lightbulb-o"></i>-->
            <!--<h4 title="提示相关设置操作时应注意的要点">操作提示</h4>-->
            <!--<span title="收起提示" id="explanationZoom" style="display: block;"></span>-->
        <!--</div>-->
        <!--<ul>-->
            <!--<li>会员列表管理, 可以给会员群发站内信、邮件等.</li>-->
            <!--<li>分销系统可以查看会员上下级信息.</li>-->
        <!--</ul>-->
    <!--</div>-->
    <div class="flexigrid">
        <div class="mDiv">
            <div class="ftitle">
                <h3>城市合伙人列表</h3>
                <h5>(共<span id="user_count"></span>条记录)</h5>
            </div>
            <div title="刷新数据" class="pReload"><i class="fa fa-refresh"></i></div>
            <form class="navbar-form form-inline" method="post"  id="search-form2">
                <input type="hidden" name="order_by" value="user_id">
                <input type="hidden" name="sort" value="desc">
                <input type="hidden" name="account" value="" id="account" />
                <input type="hidden" name="nickname" value="" id="nickname" />
                <!--分销时查看下级人数都有哪些-->
                <div class="sDiv">
                    <div class="sDiv2">
                        <select onchange="get_city(this)" id="province" name="province"  title="请选择所在省份">
                            <option value="">选择省份</option>
                            <volist name="province" id="vo">
                                <option value="{$vo.id}" >{$vo.name}</option>
                            </volist>
                        </select>
                    </div>
                    <div class="sDiv2">
                        <select onchange="get_area(this)" id="city" name="city" title="请选择所在城市">
                            <option value="">选择城市</option>
                            <volist name="city" id="vo">
                                <option value="{$vo.id}">{$vo.name}</option>
                            </volist>
                        </select>
                    </div>
                    <div class="sDiv2">
                        <select id="district" name="district" title="请选择所在区县">
                            <option value="">选择区域</option>
                            <volist name="area" id="vo">
                                <option value="{$vo.id}">{$vo.name}</option>
                            </volist>
                        </select>
                    </div>
                    <div class="sDiv2">
                        <select class="select" name="search_type" id="search_type">
                            <option value="nickname">城市合伙人昵称</option>
                            <option value="search_key">城市合伙人账户</option>
                        </select>
                        <input type="text" id="search_key" size="30" class="qsbox" placeholder="查询"
                               value="{$Request.param.search_key}">
                        <input type="button" class="btn" onclick="ajax_get_table('search-form2',1)" value="搜索">
                    </div>
                </div>
            </form>
        </div>
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0">
                    <thead>
                    <tr>
                        <th class="sign" axis="col0">
                            <div style="width: 24px;"><i class="ico-check"></i></div>
                        </th>
                        <th align="left" abbr="user_id" axis="col3" class="">
                            <div style="text-align: center; width: 40px;" class="">ID</div>
                        </th>
                        <th align="left" abbr="nickname" axis="col4" class="">
                            <div style="text-align: center; width: 50px;" class="">昵称</div>
                        </th>
                        <th align="center" abbr="distribut_level" axis="col5" class="">
                            <div style="text-align: center; width: 60px;" class="">等级</div>
                        </th>
                        <th align="center" abbr="pinfo.nickname" axis="col5" class="">
                            <div style="text-align: center; width: 50px;" class="">上级</div>
                        </th>
                        <th align="center" abbr="total_amount" axis="col6" class="">
                            <div style="text-align: center; width: 50px;" class="">总收益</div>
                        </th>
                        <th align="center" abbr="total_amount" axis="col6" class="">
                            <div style="text-align: center; width: 50px;" class="">余额</div>
                        </th>
                        <th align="center" abbr="friend_num" axis="col6" class="">
                            <div style="text-align: center; width: 50px;" class="">合伙人数</div>
                        </th>
                        <th align="center" abbr="friend_money" axis="col6" class="">
                            <div style="text-align: center; width: 50px;" class="">推荐收益</div>
                        </th>
                        <th align="center" abbr="next_mznum" axis="col6" class="">
                            <div style="text-align: center; width: 70px;" class="">下级门诊数</div>
                        </th>
                        <th align="center"  abbr="next_mzmoney" axis="col6" class="">
                            <div style="text-align: center; width: 100px;" class="">推荐下级门诊收益</div>
                        </th>
                        <th align="center" abbr="next_mzmoney" axis="col6" class="">
                            <div style="text-align: center; width: 100px;" class="">下级门诊订货收益</div>
                        </th>
                        <th align="center" abbr="second_mznum" axis="col6" class="">
                            <div style="text-align: center; width: 70px;" class="">二级门诊数</div>
                        </th>
                        <th align="center" abbr="second_mzmoney" axis="col6" class="">
                            <div style="text-align: center; width: 100px;" class="">推荐二级门诊收益</div>
                        </th>
                        <th align="center" abbr="second_mzmoney" axis="col6" class="">
                            <div style="text-align: center; width: 100px;" class="">二级门诊订货收益</div>
                        </th>
                        <th align="center" axis="col1" class="handle">
                            <div style="text-align: center; width: 60px;">操作</div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <if condition = "session('user_id') eq 0">
        <div class="tDiv">
            <div class="tDiv2">
                <div class="fbutton">
                    <a href="{:U('Distribut/add_user')}">
                        <div class="add" title="添加城市合伙人">
                            <span><i class="fa fa-plus"></i>添加城市合伙人</span>
                        </div>
                    </a>
                </div>
                <div class="fbutton">
                    <a href="javascript:;" onclick="exportUser()">
                        <div class="add" title="导出城市合伙人">
                            <span><i class="fa fa-share"></i>导出城市合伙人</span>
                        </div>
                    </a>
                </div>
                <div class="fbutton">
                    <a onclick="send_message();">
                        <div class="add" title="发送站内信">
                            <span><i class="fa fa-send"></i>发送站内信</span>
                        </div>
                    </a>
                </div>
                <!--<div class="fbutton">-->
                    <!--<a onclick="send_mail();">-->
                        <!--<div class="add" title="发送邮件">-->
                            <!--<span><i class="fa fa-send-o"></i>发送邮件</span>-->
                        <!--</div>-->
                    <!--</a>-->
                <!--</div>-->
            </div>
            <div style="clear:both"></div>
        </div>
        </if>
        <div class="bDiv" style="height: auto;" id="ajax_return">
        </div>
    </div>
</div>
<script>
    $(document).ready(function(){
        // 点击刷新数据
        var ssort = 'sdesc';
        var on_sclick = 0;
        $('.hDivBox > table>thead>tr>th').hover(
            function () {
                if(typeof($(this).attr('abbr')) == "undefined"){
                    return false;
                }
                $(this).addClass('thOver');
                if($(this).hasClass('sorted')){
                    if(ssort == 'sdesc'){
                        $(this).find('div').removeClass('sdesc');
                        $(this).find('div').addClass('sasc');
                    }else{
                        $(this).find('div').removeClass('sasc');
                        $(this).find('div').addClass('sdesc');
                    }
                }else{
                    $(this).find('div').addClass(ssort);
                }
            }, function () {
                    if(typeof($(this).attr('abbr')) == "undefined"){
                        return false;
                    }
                    if(on_sclick == 0){
                        if($(this).hasClass('sorted')){
                            if(ssort == 'sdesc'){
                                $(this).find('div').removeClass('sasc');
                                $(this).find('div').addClass('sdesc');
                            }else{
                                $(this).find('div').removeClass('sdesc');
                                $(this).find('div').addClass('sasc');
                            }
                        }else{
                            $(this).find('div').removeClass(ssort);
                        }
                    }
                    $(this).removeClass("thOver");
                    on_sclick = 0;
            }
        );
        $('.hDivBox > table>thead>tr>th').click(function(){
            if(typeof($(this).attr('abbr')) == "undefined"){
                return false;
            }
            if($(this).hasClass('sorted')){
                $(this).find('div').removeClass(ssort);
                if(ssort == 'sdesc'){
                    ssort = 'sasc';
                }else{
                    ssort = 'sdesc';
                }
                $(this).find('div').addClass(ssort);
                on_sclick = 1;
            }else{
                $('.hDivBox > table>thead>tr>th').removeClass('sorted');
                $('.hDivBox > table>thead>tr>th').find('div').removeClass(ssort);
                $(this).addClass('sorted');
                $(this).find('div').addClass(ssort);
                var hDivBox_th_index = $(this).index();
                var flexigrid_tr =   $('#flexigrid > table>tbody>tr')
                flexigrid_tr.each(function(){
                    $(this).find('td').removeClass('sorted');
                    $(this).children('td').eq(hDivBox_th_index).addClass('sorted');
                });
            }
            sort($(this).attr('abbr'));
        });

        $('.fa-refresh').click(function(){
            location.href = location.href;
        });
        ajax_get_table('search-form2',1);

    });
    //选中全部
    $('.hDivBox .sign').click(function(){
        var sign = $('#flexigrid > table>tbody>tr');
       if($(this).parent().hasClass('trSelected')){
           sign.each(function(){
               $(this).removeClass('trSelected');
           });
           $(this).parent().removeClass('trSelected');
       }else{
           sign.each(function(){
               $(this).addClass('trSelected');
           });
           $(this).parent().addClass('trSelected');
       }
    })

    // ajax 抓取页面
    function ajax_get_table(tab,page){
        var search_key = $.trim($('#search_key').val());
        var search_type = $.trim($('#search_type').val());
        if(search_key.length > 0){
            if(search_type == 'search_key'){
                $('#account').val(search_key);
                $('#nickname').val('');
            }else{
                $('#nickname').val(search_key);
                $('#account').val('');
            }
        }
        cur_page = page; //当前页面 保存为全局变量
        $.ajax({
            type : "POST",
            url:"/index.php/Admin/Distribut/ajaxindex/p/"+page,//+tab,
            data : $('#'+tab).serialize(),// 你的formid
            success: function(data){
                $("#ajax_return").html('');
                $("#ajax_return").append(data);
            }
        });
    }

    //发送邮件
    function send_mail()
    {
        var obj = $('.trSelected');
        var url = "{:U('Admin/Distribut/sendMail')}";
        if(obj.length > 0){
            var check_val = [];
            obj.each(function(){
                check_val.push($(this).attr('data-id'));
            });
            url += "?user_id_array="+check_val;
            layer.open({
                type: 2,
                title: '发送邮箱',
                shadeClose: true,
                shade: 0.8,
                area: ['580px', '480px'],
                content: url
            });
        }else{
            layer.msg('请选择会员',{icon:2});
        }
    }

    //发送站内信
    function send_message()
    {
        var obj = $('.trSelected');
        var url = "{:U('Admin/Distribut/sendMessage')}";
        if(obj.length > 0){
            var check_val = [];
            obj.each(function(){
                check_val.push($(this).attr('data-id'));
            });
            url += "?user_id_array="+check_val;
        }
            layer.open({
                type: 2,
                title: '站内信',
                shadeClose: true,
                shade: 0.8,
                area: ['580px', '480px'],
                content: url
            });
    }

    // 点击排序
    function sort(field)
    {
        $("input[name='order_by']").val(field);
        var v = $("input[name='sort']").val() == 'desc' ? 'asc' : 'desc';
        $("input[name='sort']").val(v);
        ajax_get_table('search-form2',cur_page);
    }
    /**
     * 回调函数
     */
    function call_back(v) {
        layer.closeAll();
        if (v == 1) {
            layer.msg('发送成功',{icon:1});
        } else {
            layer.msg('发送失败',{icon:2});
        }
    }
    
    function exportUser() {
        $('input[name="user_ids"]').val('');
        $('#search-form2').attr('action',"{:U('Distribut/export_cityuser')}")
        var selected_ids = '';
        $('.trSelected' , '#flexigrid').each(function(i){
            selected_ids += $(this).data('id')+',';
        });
        if(selected_ids != ''){
            $('input[name="user_ids"]').val(selected_ids.substring(0,selected_ids.length-1));
        }
        $('#search-form2').submit();
    }
</script>
</body>
</html>